#include "ValueFunctionRequestMessage.h"

#include <stdio.h>
#include "MREAgent.h"

namespace messaging{

ValueFunctionRequestMessage::ValueFunctionRequestMessage(const char* msg)
:GenericMessage(msg)
{
//	printf("content is: '%s'\n", content.data()); 
}



ValueFunctionRequestMessage::~ValueFunctionRequestMessage(void)
{
}


vector<Observation> ValueFunctionRequestMessage::parse()
{

	vector<string> tokens; 
	tokenize(content, tokens, ":"); 

	string totalStr = tokens[0]; 
	int total = str2int(totalStr); 

	
	values.clear(); 
//	values.resize(total); 

	string dataContent = tokens[1]; 
	tokenize(dataContent, tokens, ":"); 

	int s = total; 
	for(int i=1; i<= s; i++) //for each observation
	{
//		printf("i: %d/%d: %s\n", i, s, tokens[i].data()); 
		//split into individual numbers
		vector<string> obsTokens; 
		tokenize(tokens[i], obsTokens, "_"); 
		int numInt = str2int(obsTokens[0]); 
		int numDouble = str2int(obsTokens[numInt+1]); 
		printf("dimension is: %d\n", numDouble); 
		Observation obs = new Observation_type[numDouble]; 
		for(int j= 0; j< numDouble; j++)
			obs[j] = str2double(obsTokens[numInt+2+j]); 

		MREAgent::printObservation(obs); 

		values.push_back(obs); 
		MREAgent::printObservation(values.back()); 

	}


	for(int i=0; i< values.size(); i++)
		MREAgent::printObservation(values[i]); 

	return values; 
}
}

